package ym.controller.front.house;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ym.pojo.House;
import ym.service.HouseService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 房源
 */
@CrossOrigin
@RestController
@RequestMapping("/front/house")
public class FrontHouseCon {
    @Autowired
    private HouseService houseService;

    /**
     * 根据id查询【封装图片】
     *
     * @param houseId
     * @return 查询结果
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer houseId) {
        House house = houseService.findById(houseId);
        return BaseResult.ok(house);
    }

    /**
     * 分页查询【上架的】
     *
     * @param search 搜索条件
     * @param page   当前页
     * @param size   每页大小
     * @return
     */
    @GetMapping("/search")
    public BaseResult search(String search, int page, int size) {
        Page<House> housePage = houseService.searchWithUse(search, page, size);
        return BaseResult.ok(housePage);
    }

    /**
     * 根据小区查询所有【上架的】
     *
     * @param housePlotId
     * @return
     */
    @GetMapping("/findAllByPlotId")
    public BaseResult findAllByPlotId(Integer housePlotId) {
        List<House> houseList = houseService.findAllByPlotId(housePlotId);
        return BaseResult.ok(houseList);
    }
}
